package com.tutor.lzm.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tutor.lzm.R;
import com.tutor.lzm.http.response.TutorRequiresSearchBean;
import com.tutor.syslib.util.TextUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zzgpc on 2017-9-6.
 * 做家教适配器
 */
public class BecomeTutorAdapter extends BaseAdapter {
    private Context mCtx;
    private List<TutorRequiresSearchBean> list;

    public BecomeTutorAdapter(Context context, List<TutorRequiresSearchBean> list) {
        this.mCtx = context;
        this.list = list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mCtx).inflate(R.layout.item_become_tutor, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        TutorRequiresSearchBean bean = list.get(position);
        viewHolder.tvSubject.setText(bean.categoryIdText);
        viewHolder.tvTutor.setText("需" + bean.gradeIdText + bean.categoryIdText + "家教");
        viewHolder.tvTeachPrice.setText(bean.price + "元/小时");
        viewHolder.tvMarker1.setText(bean.teacherTypeText);
        viewHolder.tvArea.setText(bean.cityText + bean.areaText);
        if (!TextUtil.isNull(bean.workingAge)) {
            viewHolder.tvMarker2.setText("教龄" + bean.workingAge + "年");
        } else {
            viewHolder.tvMarker2.setVisibility(View.GONE);
        }
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tv_subject)
        TextView tvSubject;
        @BindView(R.id.tv_tutor)
        TextView tvTutor;
        @BindView(R.id.tv_teach_price)
        TextView tvTeachPrice;
        @BindView(R.id.tv_marker1)
        TextView tvMarker1;
        @BindView(R.id.tv_marker2)
        TextView tvMarker2;
        @BindView(R.id.tv_area)
        TextView tvArea;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
